package com.cheng.spider.analyze;

import org.apache.http.HttpResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AbstractStatusCodeResolver implements StatusCodeResolver {

    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractStatusCodeResolver.class);

    @Override
    public void check(HttpResponse response) {
        int code = response.getStatusLine().getStatusCode();
        LOGGER.info("响应状态码：" + code);
        switch (code) {
            case 200:
                case200(response);
                break;
            case 302:
                case302(response);
                break;
            case 304:
                case304(response);
                break;
            case 403:
            case 404:
            case 500:
            case 502:
            default:
                caseErrorCode(response);
                break;
        }
    }

    protected abstract void caseErrorCode(HttpResponse response);

    protected abstract void case304(HttpResponse response);

    protected abstract void case302(HttpResponse response);

    protected abstract void case200(HttpResponse response);
}
